package com.itheima.web.servlet;

import com.itheima.domain.User;
import com.itheima.service.impl.UserServiceImpl;
import com.sun.xml.internal.bind.v2.model.core.ID;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//修改
@WebServlet("/userFindServlet")
public class UserFindServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取要修改用户的id
        String id = request.getParameter("id");
        //调用service查询
        UserServiceImpl servlet = new UserServiceImpl();
        User user = servlet.findById(id);

        //将对象存入请求域中 转发update.jsp进行数据回显
        request.setAttribute("user",user);
        request.getRequestDispatcher("/update.jsp").forward(request,response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
